package com.swt.agy.backend.service.impl;

import com.swt.agy.backend.dao.DictCityDao;
import com.swt.agy.backend.model.entity.DictCity;
import com.swt.agy.backend.model.entity.DictCityExample;
import com.swt.agy.backend.service.DictCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class DictCityServiceImpl implements DictCityService {

    @Autowired
    private DictCityDao dictCityDao;



    @Override
    public List<DictCity> getAllDictCity() {
        List<DictCity> ls = dictCityDao.selectByExample(new DictCityExample());
       // System.out.println(ls);
        return ls;
    }

    @Override
    public List<DictCity> getDictCity(Integer provinceId) {
        DictCityExample dictCityExample=new DictCityExample();
        DictCityExample.Criteria criteria = dictCityExample.createCriteria();
        criteria.andProvinceIdEqualTo(provinceId);

        List<DictCity> list = dictCityDao.selectByExample(dictCityExample);
        System.out.println(list);
        return list;
    }

    @Override
    public List<DictCity> findDictCityByProId(Integer provinceId) {
        return dictCityDao.selectDictCityByProvinceId(provinceId);
    }

    @Override
    public List<DictCity> selectByCityName(String cityName) {
        List<DictCity> dictCities= dictCityDao.selectByCityName(cityName);
        ArrayList cityNames=new ArrayList();
        for (int i = 0; i <dictCities.size() ; i++) {
            cityNames.add(dictCities.get(i).getCityName());
        }
        return cityNames;
    }


}
